package com.atguigu.flink.chapter10.collection;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class CollectionDemo1 {
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());

        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        tEnv.executeSql("create table t1(" +
                " id string, " +
                " name string " +
                ")with(" +
                "  'connector' = 'kafka', " +
                "  'topic' = 't1', " +
                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
                "  'properties.group.id' = 'atguigu', " +
                "  'scan.startup.mode' = 'latest-offset', " +
                "  'format' = 'csv' " +
                ")");

        tEnv.executeSql("create table t2(" +
                " id string, " +
                " name string " +
                ")with(" +
                "  'connector' = 'kafka', " +
                "  'topic' = 't2', " +
                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
                "  'properties.group.id' = 'atguigu', " +
                "  'scan.startup.mode' = 'latest-offset', " +
                "  'format' = 'csv' " +
                ")");

        //两个表的并集
        tEnv.sqlQuery("select * from t1 union select * from t2").execute().print();
        //两个表的交集
        //tEnv.sqlQuery("select * from t1 Intersect select from t2").execute().print();
        //两个表的差集
        //tEnv.sqlQuery("select * from t1 expect select from t2").execute().print();

    }
}



//public class CollectionDemo1 {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//
//        tEnv.executeSql("create table t1(" +
//                "id string ," +
//                "name string" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 't1', " +
//                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
//                "  'properties.group.id' = 'atguigu', " +
//                "  'scan.startup.mode' = 'latest-offset', " +
//                "  'format' = 'csv' " +
//                ")");
//
//        tEnv.executeSql("create table t2(" +
//                "id string ," +
//                "name string" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 't2', " +
//                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
//                "  'properties.group.id' = 'atguigu', " +
//                "  'scan.startup.mode' = 'latest-offset', " +
//                "  'format' = 'csv' " +
//                ")");
//
//        //两张表的并集
//        //tEnv.sqlQuery("select * from t1 union select * from t2");
//        //两张表的交集
//        //tEnv.sqlQuery("select * from t1 intersect select * from t2");
//        //两张表的交集
//        tEnv.sqlQuery("select * form t1 expect select * from t2");
//    }
//}

//public class CollectionDemo1 {
//    public static void main(String[] args) {
//        Configuration conf = new Configuration();
//        conf.setInteger("rest.port",2000);
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//        env.setParallelism(1);
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//
//        tEnv.executeSql("create table t1(" +
//                "id string," +
//                "name string" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 't1', " +
//                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
//                "  'properties.group.id' = 'atguigu', " +
//                "  'scan.startup.mode' = 'latest-offset', " +
//                "  'format' = 'csv' " +
//                ")");
//
//        tEnv.executeSql("create table t2(" +
//                "id string," +
//                "name string" +
//                ") with(" +
//                "  'connector' = 'kafka', " +
//                "  'topic' = 't1', " +
//                "  'properties.bootstrap.servers' = 'hadoop102:9092', " +
//                "  'properties.group.id' = 'atguigu', " +
//                "  'scan.startup.mode' = 'latest-offset', " +
//                "  'format' = 'csv' " +
//                ")");
//
//
//        //两个表的并集
//        tEnv.sqlQuery("select * from t1 union select * from t2");
//        //两个表的交集
//        tEnv.sqlQuery("select * from t1 intersect select * from t2");
//        //两个表的差集
//        tEnv.sqlQuery("select * from t1 expect select * from t2");
//    }
//}
